# Author    :Dun_Hz
# Time      :2024/7/29 9:19
# 计数排序
import random


def count_sort(li, max_num=10):
    ltmp=[0 for _ in range(max_num+1)]        # 创建新列表存储计数，比如3出现2次: ltmp[3]=2
    for i in li:
        ltmp[i] += 1
    li.clear()
    for ind,val in enumerate(ltmp):
        for i in range(val):
            li.append(ind)

if __name__=="__main__":
    li=[random.randint(0,10) for _ in range(20)]
    print(li)
    count_sort(li)
    print(li)